﻿//
// Yedda Twitter C# Library (or more of an API wrapper) v0.1
// Written by Eran Sandler (eran AT yedda.com)
// http://devblog.yedda.com/index.php/twitter-c-library/
//
// The library is provided on a "AS IS" basis. Yedda is not repsonsible in any way 
// for whatever usage you do with it.
//
// Giving credit would be nice though :-)
//
// Get more cool dev information and other stuff at the Yedda Dev Blog:
// http://devblog.yedda.com
//
// Got a question about this library? About programming? C#? .NET? About anything else?
// Ask about it at Yedda (http://yedda.com) and get answers from real people.
//
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
//using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Net.Browser;
using System.Windows.Browser;

namespace Yedda
{
    public class Twitter
    {

        /// <summary>
        /// The output formats supported by Twitter. Not all of them can be used with all of the functions.
        /// For more information about the output formats and the supported functions Check the 
        /// Twitter documentation at: http://groups.google.com/group/twitter-development-talk/web/api-documentation
        /// </summary>
        public enum OutputFormatType
        {
            JSON,
            XML,
            RSS,
            Atom
        }

        /// <summary>
        /// The various object types supported at Twitter.
        /// </summary>
        public enum ObjectType
        {
            Statuses,
            Account,
            Users
        }

        /// <summary>
        /// The various actions used at Twitter. Not all actions works on all object types.
        /// For more information about the actions types and the supported functions Check the 
        /// Twitter documentation at: http://groups.google.com/group/twitter-development-talk/web/api-documentation
        /// </summary>
        public enum ActionType
        {
            Public_Timeline,
            User_Timeline,
            Friends_Timeline,
            Friends,
            Followers,
            Update,
            Account_Settings,
            Featured,
            Show,
            Direct_Messages,
            Report_Spam,
        }

        private string source = null;

        private string twitterClient = null;
        private string twitterClientVersion = null;
        private string twitterClientUrl = null;


        /// <summary>
        /// Source is an additional parameters that will be used to fill the "From" field.
        /// Currently you must talk to the developers of Twitter at:
        /// http://groups.google.com/group/twitter-development-talk/
        /// Otherwise, Twitter will simply ignore this parameter and set the "From" field to "web".
        /// </summary>
        public string Source
        {
            get { return source; }
            set { source = value; }
        }

        /// <summary>
        /// Sets the name of the Twitter client.
        /// According to the Twitter Fan Wiki at http://twitter.pbwiki.com/API-Docs and supported by
        /// the Twitter developers, this will be used in the future (hopefully near) to set more information
        /// in Twitter about the client posting the information as well as future usage in a clients directory.
        /// </summary>
        public string TwitterClient
        {
            get { return twitterClient; }
            set { twitterClient = value; }
        }

        /// <summary>
        /// Sets the version of the Twitter client.
        /// According to the Twitter Fan Wiki at http://twitter.pbwiki.com/API-Docs and supported by
        /// the Twitter developers, this will be used in the future (hopefully near) to set more information
        /// in Twitter about the client posting the information as well as future usage in a clients directory.
        /// </summary>
        public string TwitterClientVersion
        {
            get { return twitterClientVersion; }
            set { twitterClientVersion = value; }
        }

        /// <summary>
        /// Sets the URL of the Twitter client.
        /// Must be in the XML format documented in the "Request Headers" section at:
        /// http://twitter.pbwiki.com/API-Docs.
        /// According to the Twitter Fan Wiki at http://twitter.pbwiki.com/API-Docs and supported by
        /// the Twitter developers, this will be used in the future (hopefully near) to set more information
        /// in Twitter about the client posting the information as well as future usage in a clients directory.		
        /// </summary>
        public string TwitterClientUrl
        {
            get { return twitterClientUrl; }
            set { twitterClientUrl = value; }
        }

        protected const string TwitterBaseUrlFormat = "http://twitter.com/{0}/{1}.{2}";
        protected const string TwitterBaseUrlFormat2 = "http://twitter.com/{1}.{2}";

        protected string GetObjectTypeString(ObjectType objectType)
        {
            return objectType.ToString().ToLower();
        }

        protected string GetActionTypeString(ActionType actionType)
        {
            return actionType.ToString().ToLower();
        }

        protected string GetFormatTypeString(OutputFormatType format)
        {
            return format.ToString().ToLower();
        }

        /// <summary>
        /// Executes an HTTP GET command and retrives the information.		
        /// </summary>
        /// <param name="url">The URL to perform the GET operation</param>
        /// <param name="userName">The username to use with the request</param>
        /// <param name="password">The password to use with the request</param>
        /// <returns>The response of the request, or null if we got 404 or nothing.</returns>

        //GET 
        bool useWebClient = false;
        protected string ExecuteGetCommand(string url, string userName, string password, EventHandler callbackEvent)
        {
            if (useWebClient)
            {
                ExecuteGetCommand2(url, userName, password, callbackEvent);
            }
            else //uses httpWebRequest
            {
                ExecuteGetCommand1(url, userName, password, callbackEvent);
            }

            return string.Empty;   //we dont care about return anymore, it uses events and is async
        }

        // GET: METHOD 2 - uses WebClient
        protected string ExecuteGetCommand2(string url, string userName, string password, EventHandler callbackEvent)
        {

            // 1:
            bool httpResult = HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            bool httpsResult = HttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);


            WebClient client = new WebClient();

            if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                client.Credentials = new NetworkCredential(userName, password);
                client.UseDefaultCredentials = false;
            }

            try
            {

                client.OpenReadCompleted += ExecuteGetCommand2Completed;
                client.OpenReadAsync(new Uri(url), new CustomGetUserObject() { client = client, callback = callbackEvent });
            }
            catch (WebException ex)
            {
                //
                // Handle HTTP 404 errors gracefully and return a null string to indicate there is no content.
                //
                if (ex.Response is HttpWebResponse)
                {
                    if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                    {
                        return null;
                    }
                }

                throw ex;
            }

            return string.Empty;
        }
        void ExecuteGetCommand2Completed(object sender, OpenReadCompletedEventArgs e)
        {


            using (Stream stream = e.Result)
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    if (((CustomGetUserObject)e.UserState).callback != null) ((CustomGetUserObject)e.UserState).callback(reader.ReadToEnd(), null);

                }
            }

        }

        // GET: METHOD 1 - uses HttpWebRequest
        protected string ExecuteGetCommand1(string url, string userName, string password, EventHandler callbackEvent)
        {
            bool httpResult = HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            bool httpsResult = HttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);



            HttpWebRequest rq = (HttpWebRequest)WebRequestCreator.ClientHttp.Create(new Uri(url));
            rq.Method = "GET";
            rq.Credentials = new NetworkCredential(userName, password);
            rq.CookieContainer = new CookieContainer();
            rq.BeginGetResponse(
                new AsyncCallback(
                   r =>
                   {
                       try
                       {
                           WebResponse rs = rq.EndGetResponse(r);
                           using (Stream stream = rs.GetResponseStream())
                           {
                               using (StreamReader sr = new StreamReader(stream))
                               {
                                   if (callbackEvent != null) callbackEvent(sr.ReadToEnd(), null);
                               }
                           }


                       }
                       catch (WebException ex)
                       {

                       }
                   }), null);

            return string.Empty;
        }



        /// <summary>
        /// Executes an HTTP POST command and retrives the information.		
        /// This function will automatically include a "source" parameter if the "Source" property is set.
        /// </summary>
        /// <param name="url">The URL to perform the POST operation</param>
        /// <param name="userName">The username to use with the request</param>
        /// <param name="password">The password to use with the request</param>
        /// <param name="data">The data to post</param> 
        /// <returns>The response of the request, or null if we got 404 or nothing.</returns>
        byte[] messageToSendInBytes;
        protected void ExecutePostCommand(string url, string userName, string password, string data)
        {
            //App.Current.HasElevatedPermissions = true;
            // 1:
            bool httpResult = HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
            bool httpsResult = HttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);


            // 2:
            string uri = url;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);


            request.Credentials = new NetworkCredential(userName, password);
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
            request.Headers["X-Twitter-Client"] = "SilverTweets";
            request.Headers["X-Twitter-Version"] = "1.0";
            request.Headers["X-Twitter-URL"] = @"HTTP://WWW.MahTweets.com";

            string parameters = data; //string.Format("status={0}&source={1}", HttpUtility.HtmlEncode(data), "SilverTweets");
            messageToSendInBytes = System.Text.Encoding.UTF8.GetBytes(parameters);


            Stream os = null;
            request.BeginGetRequestStream(new AsyncCallback(ExecutePostCommand_RequestCallback), request);

        }


        protected void ExecutePostCommand_RequestCallback(IAsyncResult result)
        {

            HttpWebRequest request = (HttpWebRequest)result.AsyncState;
            Stream postStream = request.EndGetRequestStream(result);
            postStream.Write(messageToSendInBytes, 0, messageToSendInBytes.Length);
            postStream.Close();


            request.BeginGetResponse(new AsyncCallback(ExecutePostCommand_ResponseCallback), request);

        }

        private void ExecutePostCommand_ResponseCallback(IAsyncResult result)
        {

            HttpWebRequest request = (HttpWebRequest)result.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result);
            Stream streamResponse = response.GetResponseStream();
            StreamReader reader = new StreamReader(streamResponse);
            string responseString = reader.ReadToEnd();
            streamResponse.Close();
            reader.Close();
            response.Close();

        }




        #region Public_Timeline
        public event EventHandler GetPublicTimelineComplete;
        public string GetPublicTimeline(OutputFormatType format)
        {
            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Public_Timeline), GetFormatTypeString(format));
            return ExecuteGetCommand(url, null, null, GetPublicTimelineComplete);
        }

        public string GetPublicTimelineAsJSON()
        {
            return GetPublicTimeline(OutputFormatType.JSON);
        }

        public XDocument GetPublicTimelineAsXML(OutputFormatType format)
        {
            if (format == OutputFormatType.JSON)
            {
                throw new ArgumentException("GetPublicTimelineAsXml supports only XML based formats (XML, RSS, Atom)", "format");
            }

            string output = GetPublicTimeline(format);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        public XDocument GetPublicTimelineAsXML()
        {
            return GetPublicTimelineAsXML(OutputFormatType.XML);
        }

        public XDocument GetPublicTimelineAsRSS()
        {
            return GetPublicTimelineAsXML(OutputFormatType.RSS);
        }

        public XDocument GetPublicTimelineAsAtom()
        {
            return GetPublicTimelineAsXML(OutputFormatType.Atom);
        }

        #endregion

        #region User_Timeline
        public event EventHandler GetUserTimelineComplete;
        public string GetUserTimeline(string userName, string password, string IDorScreenName, OutputFormatType format)
        {
            string url = null;
            if (string.IsNullOrEmpty(IDorScreenName))
            {
                url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.User_Timeline), GetFormatTypeString(format));
            }
            else
            {
                url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.User_Timeline) + "/" + IDorScreenName, GetFormatTypeString(format));
            }

            return ExecuteGetCommand(url, userName, password, GetUserTimelineComplete);
        }

        public string GetUserTimeline(string userName, string password, OutputFormatType format)
        {
            return GetUserTimeline(userName, password, null, format);
        }

        public string GetUserTimelineAsJSON(string userName, string password)
        {
            return GetUserTimeline(userName, password, OutputFormatType.JSON);
        }

        public string GetUserTimelineAsJSON(string userName, string password, string IDorScreenName)
        {
            return GetUserTimeline(userName, password, IDorScreenName, OutputFormatType.JSON);
        }

        public XDocument GetUserTimelineAsXML(string userName, string password, string IDorScreenName, OutputFormatType format)
        {
            if (format == OutputFormatType.JSON)
            {
                throw new ArgumentException("GetUserTimelineAsXML supports only XML based formats (XML, RSS, Atom)", "format");
            }

            string output = GetUserTimeline(userName, password, IDorScreenName, format);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        public XDocument GetUserTimelineAsXML(string userName, string password, OutputFormatType format)
        {
            return GetUserTimelineAsXML(userName, password, null, format);
        }

        public XDocument GetUserTimelineAsXML(string userName, string password, string IDorScreenName)
        {
            return GetUserTimelineAsXML(userName, password, IDorScreenName, OutputFormatType.XML);
        }

        public XDocument GetUserTimelineAsXML(string userName, string password)
        {
            return GetUserTimelineAsXML(userName, password, null);
        }

        public XDocument GetUserTimelineAsRSS(string userName, string password, string IDorScreenName)
        {
            return GetUserTimelineAsXML(userName, password, IDorScreenName, OutputFormatType.RSS);
        }

        public XDocument GetUserTimelineAsRSS(string userName, string password)
        {
            return GetUserTimelineAsXML(userName, password, OutputFormatType.RSS);
        }

        public XDocument GetUserTimelineAsAtom(string userName, string password, string IDorScreenName)
        {
            return GetUserTimelineAsXML(userName, password, IDorScreenName, OutputFormatType.Atom);
        }

        public XDocument GetUserTimelineAsAtom(string userName, string password)
        {
            return GetUserTimelineAsXML(userName, password, OutputFormatType.Atom);
        }
        #endregion

        #region Friends_Timeline
        public event EventHandler GetFriendsTimelineComplete;
        public string GetFriendsTimeline(string userName, string password, OutputFormatType format)
        {
            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends_Timeline), GetFormatTypeString(format));

            return ExecuteGetCommand(url, userName, password, GetFriendsTimelineComplete);
        }
        public string GetFriendsTimeline(string userName, string password, OutputFormatType format, string cursor)
        {
            string url = string.Format(TwitterBaseUrlFormat + "?cursor=" + cursor, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends_Timeline), GetFormatTypeString(format));

            return ExecuteGetCommand(url, userName, password, GetFriendsTimelineComplete);
        }

        public string GetFriendsTimelineAsJSON(string userName, string password)
        {
            return GetFriendsTimeline(userName, password, OutputFormatType.JSON);
        }
        public string GetFriendsTimelineAsJSONWithCursor(string userName, string password, string cursor)
        {
            return GetFriendsTimeline(userName, password, OutputFormatType.JSON, cursor);
        }

        public XDocument GetFriendsTimelineAsXML(string userName, string password, OutputFormatType format)
        {
            if (format == OutputFormatType.JSON)
            {
                throw new ArgumentException("GetFriendsTimelineAsXML supports only XML based formats (XML, RSS, Atom)", "format");
            }

            string output = GetFriendsTimeline(userName, password, format);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        public XDocument GetFriendsTimelineAsXML(string userName, string password)
        {
            return GetFriendsTimelineAsXML(userName, password, OutputFormatType.XML);
        }

        public XDocument GetFriendsTimelineAsRSS(string userName, string password)
        {
            return GetFriendsTimelineAsXML(userName, password, OutputFormatType.RSS);
        }

        public XDocument GetFriendsTimelineAsAtom(string userName, string password)
        {
            return GetFriendsTimelineAsXML(userName, password, OutputFormatType.Atom);
        }

        #endregion

        #region Friends
        public event EventHandler GetFriendsComplete;
        public string GetFriends(string userName, string password, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("GetFriends support only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends), GetFormatTypeString(format));
            return ExecuteGetCommand(url, userName, password, GetFriendsComplete);
        }
        public string GetFriends(string userName, string password, OutputFormatType format, string cursor)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("GetFriends support only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat + "?cursor=" + cursor, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends), GetFormatTypeString(format));
            return ExecuteGetCommand(url, userName, password, GetFriendsComplete);
        }

        public string GetFriends(string userName, string password, string IDorScreenName, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("GetFriends support only XML and JSON output format", "format");
            }

            string url = null;
            if (string.IsNullOrEmpty(IDorScreenName))
            {
                url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends), GetFormatTypeString(format));
            }
            else
            {
                url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Friends) + "/" + IDorScreenName, GetFormatTypeString(format));
            }

            return ExecuteGetCommand(url, userName, password, GetFriendsComplete);
        }

        public string GetFriendsAsJSON(string userName, string password, string IDorScreenName)
        {
            return GetFriends(userName, password, IDorScreenName, OutputFormatType.JSON);
        }

        public string GetFriendsAsJSON(string userName, string password)
        {
            return GetFriendsAsJSON(userName, password, null);
        }

        public string GetFriendsAsJSONWithCursor(string userName, string password, string cursor)
        {
            return GetFriends(userName, password, OutputFormatType.JSON, cursor);
        }

        public XDocument GetFriendsAsXML(string userName, string password, string IDorScreenName)
        {
            string output = GetFriends(userName, password, IDorScreenName, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        public XDocument GetFriendsAsXML(string userName, string password)
        {
            return GetFriendsAsXML(userName, password, null);
        }

        #endregion

        #region Followers
        public event EventHandler GetFollowersComplete;
        public string GetFollowers(string userName, string password, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("GetFollowers supports only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Followers), GetFormatTypeString(format));
            return ExecuteGetCommand(url, userName, password, GetFollowersComplete);
        }

        public string GetFollowersAsJSON(string userName, string password)
        {
            return GetFollowers(userName, password, OutputFormatType.JSON);
        }

        public XDocument GetFollowersAsXML(string userName, string password)
        {
            string output = GetFollowers(userName, password, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        #endregion

        #region Update
        public event EventHandler UpdateComplete;
        public string Update(string userName, string password, string status, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("Update support only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Update), GetFormatTypeString(format));
            string data = string.Format("status={0}", HttpUtility.UrlEncode(status));

            //return ExecutePostCommand(url, userName, password, data);
            ExecutePostCommand(url, userName, password, data);

            return "";
        }

        public string UpdateAsJSON(string userName, string password, string text)
        {
            return Update(userName, password, text, OutputFormatType.JSON);
        }

        public XDocument UpdateAsXML(string userName, string password, string text)
        {
            string output = Update(userName, password, text, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        #endregion

        #region Featured
        public event EventHandler GetFeaturedComplete;
        public string GetFeatured(string userName, string password, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("GetFeatured supports only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Statuses), GetActionTypeString(ActionType.Featured), GetFormatTypeString(format));
            return ExecuteGetCommand(url, userName, password, GetFeaturedComplete);
        }

        public string GetFeaturedAsJSON(string userName, string password)
        {
            return GetFeatured(userName, password, OutputFormatType.JSON);
        }

        public XDocument GetFeaturedAsXML(string userName, string password)
        {
            string output = GetFeatured(userName, password, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        #endregion

        #region Show
        public event EventHandler ShowComplete;
        public string Show(string userName, string password, string IDorScreenName, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("Show supports only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat, GetObjectTypeString(ObjectType.Users), GetActionTypeString(ActionType.Show) + "/" + IDorScreenName, GetFormatTypeString(format));
            return ExecuteGetCommand(url, userName, password, ShowComplete);
        }

        public string ShowAsJSON(string userName, string password, string IDorScreenName)
        {
            return Show(userName, password, IDorScreenName, OutputFormatType.JSON);
        }

        public XDocument ShowAsXML(string userName, string password, string IDorScreenName)
        {
            string output = Show(userName, password, IDorScreenName, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }

        #endregion

        #region Lists
        public event EventHandler CreateListComplete;


        #endregion

        #region Spam
        public event EventHandler ReportSpamUserComplete;
        public string ReportSpamUser(string userName, string password, string screenName, OutputFormatType format)
        {
            if (format != OutputFormatType.JSON && format != OutputFormatType.XML)
            {
                throw new ArgumentException("Update support only XML and JSON output format", "format");
            }

            string url = string.Format(TwitterBaseUrlFormat2, GetActionTypeString(ActionType.Report_Spam), GetFormatTypeString(format));
            string data = string.Format("screen_name={0}", HttpUtility.UrlEncode(screenName));

            //return ExecutePostCommand(url, userName, password, data);
            ExecutePostCommand(url, userName, password, data);

            return "";
        }

        public string ReportSpamUserAsJSON(string userName, string password, string screenName)
        {
            return Update(userName, password, screenName, OutputFormatType.JSON);
        }
        public XDocument ReportSpamUserAsXML(string userName, string password, string screenName)
        {
            string output = Update(userName, password, screenName, OutputFormatType.XML);
            if (!string.IsNullOrEmpty(output))
            {
                XDocument xmlDocument = XDocument.Parse(output);

                return xmlDocument;
            }

            return null;
        }
        #endregion
    }


    public class CustomGetUserObject
    {
        public HttpWebRequest request;
        public WebClient client;
        public EventHandler callback;
    }
}
